/*
 *  src/mm/mm_init.c
 *
 *  Harry Wei<harryxiyou@gmail.com> (C) 2011
 */
#include <glib.h>

#include "mm.h"

struct mm_ctrl *mm_init(uint32_t start_addr, uint32_t mem_size)
{
	g_message("enter func %s...", __func__);
	struct mm_ctrl *ctrl = (struct mm_ctrl *)g_malloc0(sizeof(struct mm_ctrl));
	if (!ctrl) {
		g_message("Allocate error!");
		return NULL;
	}
	struct free_section *free = (struct free_section *)g_malloc0(sizeof(struct free_section));
	if (!free) {
		g_message("Allocate error!");
		return NULL;
	}
	free->size = mem_size;
	free->start_addr = start_addr;
	free->end_addr = start_addr + mem_size - 1;
	free->next = NULL;
	ctrl->max_size = mem_size;
	ctrl->start_addr = start_addr;
	ctrl->end_addr = start_addr + mem_size - 1;
	ctrl->free_size = mem_size;
	ctrl->process_nums = 0;
	ctrl->allocate_size = 0;
	ctrl->free_head = free;
	ctrl->allocate_head = NULL;
	ctrl->cur_free_handler = free;
	ctrl->cur_allocate_handler = NULL;
	g_message("init success, leave func %s...", __func__);
	return ctrl;
}
